OPC Studio User's Guide and Reference
Examples - OPC XML-DA - Write a single value

.NET

// This example shows how to write a value into a single OPC XML-DA item.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

using System;
using OpcLabs.EasyOpc.DataAccess;
using OpcLabs.EasyOpc.OperationModel;

namespace DocExamples.DataAccess.Xml
{
    class WriteItemValue
    {
        public static void Main1Xml()
        {
            // Instantiate the client object.
            var client = new EasyDAClient();

            try
            {
                client.WriteItemValue(
                    "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx", 
                    "Static/Analog Types/Int", 
                    12345);
            }
            catch (OpcException opcException)
            {
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message);
            }
        }
    }
}
# This example shows how to write a value into a single OPC XML-DA item.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from System import *
from OpcLabs.EasyOpc import *
from OpcLabs.EasyOpc.DataAccess import *
from OpcLabs.EasyOpc.OperationModel import *


# Instantiate the client object.
client = EasyDAClient()

# Perform the operation
try:
    IEasyDAClientExtension.WriteItemValue(client,
        ServerDescriptor('http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx'),
        DAItemDescriptor('Static/Analog Types/Int'),
        Int32(12345))
except OpcException as opcException:
    print('*** Failure: ' + opcException.GetBaseException().Message, sep='')
    exit()

print('Finished.')
' This example shows how to write a value into a single OPC XML-DA item.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

Imports OpcLabs.EasyOpc.DataAccess
Imports OpcLabs.EasyOpc.OperationModel

Namespace DataAccess.Xml
    Partial Friend Class WriteItemValue
        Public Shared Sub Main1Xml()
            Dim client = New EasyDAClient()

            Try
                client.WriteItemValue("http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx", "Static/Analog Types/Int", 12345)
            Catch opcException As OpcException
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message)
                Exit Sub
            End Try
        End Sub
    End Class
End Namespace

COM

// This example shows how to write a value into a single OPC XML-DA item.
//
// Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

class procedure WriteItemValue.MainXml;
var
  Arguments: OleVariant;
  Client: OpcLabs_EasyOpcClassic_TLB._EasyDAClient;
  ItemValueArguments1: _DAItemValueArguments;
  Results: OleVariant;
  OperationResult: _OperationResult;
begin
  ItemValueArguments1 := CoDAItemValueArguments.Create;
  ItemValueArguments1.ServerDescriptor.UrlString := 'http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx';
  ItemValueArguments1.ItemDescriptor.ItemID := 'Static/Analog Types/Int';
  ItemValueArguments1.Value := 12345;

  Arguments := VarArrayCreate([0, 0], varVariant);
  Arguments[0] := ItemValueArguments1;

  // Instantiate the client object
  Client := CoEasyDAClient.Create;

  TVarData(Results).VType := varArray or varVariant;
  TVarData(Results).VArray := PVarArray(
    Client.WriteMultipleItemValues(Arguments));

  OperationResult := IInterface(Results[0]) as _OperationResult;
  if Not OperationResult.Succeeded then
      WriteLn(' *** Failure: ', OperationResult.Exception.GetBaseException.Message);
  
  VarClear(Results);
  VarClear(Arguments);

end;
// This example shows how to write a value into a single OPC XML-DA item.
//
// Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

$ItemValueArguments1 = new COM("OpcLabs.EasyOpc.DataAccess.OperationModel.DAItemValueArguments");
$ItemValueArguments1->ServerDescriptor->UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx";
$ItemValueArguments1->ItemDescriptor->ItemID = "Static/Analog Types/Int";
$ItemValueArguments1->Value = 12345;

$arguments[0] = $ItemValueArguments1;

// Instantiate the client object.
$Client = new COM("OpcLabs.EasyOpc.DataAccess.EasyDAClient");

$results = $Client->WriteMultipleItemValues($arguments);

$OperationResult = $results[0];
if ($OperationResult->Succeeded)
    printf("Result: success\n");
else
    printf("Result: %s\n", $OperationResult->ErrorMessageBrief);
Rem This example shows how to write a value into a single OPC XML-DA item.
Rem
Rem Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

Private Sub WriteItemValue_MainXml_Command_Click()
    OutputText = ""
    
    Dim itemValueArguments1 As New DAItemValueArguments
    itemValueArguments1.serverDescriptor.UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx"
    itemValueArguments1.ItemDescriptor.ItemId = "Static/Analog Types/Int"
    itemValueArguments1.SetValue 12345
    
    Dim arguments(0) As Variant
    Set arguments(0) = itemValueArguments1

    ' Instantiate the client object
    Dim client As New EasyDAClient

    ' Modify values of nodes
    Dim results() As Variant
    results = client.WriteMultipleItemValues(arguments)

    Dim operationResult As operationResult: Set operationResult = results(0)
    If Not operationResult.Succeeded Then
        OutputText = OutputText & "*** Failure: " & operationResult.ErrorMessageBrief & vbCrLf
    End If
End Sub
Rem This example shows how to write a value into a single OPC XML-DA item.
Rem
Rem Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

Option Explicit

Dim ItemValueArguments1: Set ItemValueArguments1 = CreateObject("OpcLabs.EasyOpc.DataAccess.OperationModel.DAItemValueArguments")
ItemValueArguments1.ServerDescriptor.UrlString = "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx"
ItemValueArguments1.ItemDescriptor.ItemID = "Static/Analog Types/Int"
ItemValueArguments1.Value = 12345

Dim arguments(0)
Set arguments(0) = ItemValueArguments1

Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.DataAccess.EasyDAClient")
Dim results: results = Client.WriteMultipleItemValues(arguments)

Dim OperationResult: Set OperationResult = results(0)
If OperationResult.Succeeded Then
    WScript.Echo "Result: success"
Else
    WScript.Echo "Result: " & OperationResult.Exception.GetBaseException.Message
End If

 

OPC Data Client supports OPC XML-DA also on Linux and macOS.
See Also

Examples - OPC Data Access

Conceptual